<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增人员信息')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
   <!-- <th:block th:include="include :: jasny-bootstrap-css" />-->
</head>
<body>
    <div class="main-content">
        <form class="form-horizontal m" id="form-user-add">
            <input name="deptId" type="hidden" id="treeId"/>
            <h4 class="form-header h4">基本信息</h4>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">用户名称：</label>
                        <div class="col-sm-8">
                            <!--<input name="userName" placeholder="请输入用户名称" class="form-control" type="text" maxlength="30" required>-->
                            <input id="userName" name="userName" placeholder="请输入用户名名称" class="form-control" type="text" maxlength="30" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">归属部门：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属部门" class="form-control">
                                <span class="input-group-addon"><i class="fa fa-search"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">人员类型：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <select name="userType" class="form-control m-b">
                                    <option value="00">常驻</option>
                                    <option value="01">临时</option>
                                </select>
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">联系电话：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input id="phonenumber" name="phonenumber" placeholder="请输入联系电话" class="form-control" type="text" maxlength="11">
                                <span class="input-group-addon"><i class="fa fa-mobile"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">人员性别：</label>
                        <div class="col-sm-8">
                            <select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">年龄：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input id="age" name="age" placeholder="请输入年龄" class="form-control" type="text" maxlength="3">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">人员状态：</label>
                        <div class="col-sm-8">
                            <select name="userStatus" class="form-control m-b" th:with="type=${@dict.getType('zhmk_user_status')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label">岗位：</label>
                        <div class="col-xs-8">
                            <select id="post" class="form-control select2-multiple" multiple>
                                <option th:each="post:${posts}" th:value="${post.postId}" th:text="${post.postName}" th:disabled="${post.status == '1'}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">人员头像：</label>
                        <div class="col-sm-4">
                            <div class="fileinput fileinput-new" data-provides="fileinput">
                                <div>
                                    <span class="btn btn-white btn-file">
                                        <span class="fileinput-new">选择图片</span>
                                        <span class="fileinput-exists">更改</span>
                                        <input type="file">
                                    </span>
                                    <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                                </div>
                                <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px;"></div>
                            </div>
                            <!--<label class="toggle-switch switch-solid">
                                <div class="text-center">
                                    <p class="user-info-head" onclick="avatar()"><img class="img-circle img-sm" th:src="@{/img/profile.jpg}"></p>
                                    <p><a href="javascript:avatar()">修改头像</a></p>
                                </div>
                            </label>-->
                        </div>
                    </div>
                </div>
            </div>
            <!--<div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-xs-2 control-label">状态：</label>
                        <div class="col-xs-10">
                            <label class="toggle-switch switch-solid">
                                <input type="checkbox" id="userStatus" checked>
                                <span></span>
                            </label>
                        </div>
                    </div>
                </div>
            </div>-->
            <h4 class="form-header h4">其他信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-xs-2 control-label">备注：</label>
                        <div class="col-xs-10">
                            <textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
                        </div>
                    </div>
                </div>
            </div>

           <!-- <div class="form-group">
                <label class="col-sm-3 control-label">部门ID：</label>
                <div class="col-sm-8">
                    <input name="deptId" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">姓名：</label>
                <div class="col-sm-8">
                    <input name="userName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">人员类型：</label>
                <div class="col-sm-8">
                    <select name="userType" class="form-control m-b">
                        <option value="">所有</option>
                    </select>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">联系电话：</label>
                <div class="col-sm-8">
                    <input name="phonenumber" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">性别：</label>
                <div class="col-sm-8">
                    <select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">年龄：</label>
                <div class="col-sm-8">
                    <input name="age" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">头像路径：</label>
                <div class="col-sm-8">
                    <input name="avatar" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">人员状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <input type="radio" name="userStatus" value="">
                        <label th:for="userStatus" th:text="未知"></label>
                    </div>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">删除标志：</label>
                <div class="col-sm-8">
                    <input name="delFlag" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">临时人员最后使用时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="pwdUpdateDate" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>-->

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script>
        var prefix = ctx + "zhmk/user"

        $("#form-user-add").validate({
            onkeyup: false,
            rules:{
                userName:{
                    minlength: 2,
                    maxlength: 20,
                    remote: {
                        url: prefix + "/checkLoginNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "userName": function() {
                                return $.common.trim($("#userName").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                phonenumber:{
                    isPhone:true,
                    remote: {
                        url: prefix + "/checkPhoneUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "phonenumber": function () {
                                return $.common.trim($("#phonenumber").val());
                            }
                        },
                        dataFilter: function (data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
            },
            messages: {
                "userName": {
                    remote: "用户已经存在"
                },
                "phonenumber":{
                    remote: "手机号码已经存在"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            var chrtype = [[${#strings.defaultString(@config.getKey('sys.account.chrtype'), 0)}]];
            if ($.validate.form()) {
                var data = $("#form-user-add").serializeArray();
                //var userStatus = $("input[id='userStatus']").is(':checked') == true ? 0 : 1;
                var postIds = $.form.selectSelects("post");
                //data.push({"name": "userStatus", "value": userStatus});
                data.push({"name": "postIds", "value": postIds});
                $.operate.save(prefix + "/add", data);
            }
        }

        /* 用户管理-新增-选择部门树 */
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "zhmk/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门单位',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }

        $(function() {
            $('#post').select2({
                placeholder: "请选择岗位",
                allowClear: true
            });
        })

        /*用户管理-头像*/
        function avatar() {
            var url = prefix + "/avatar";
            top.layer.open({
                type: 2,
                area: [$(window).width() + 'px', $(window).height() + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "修改头像",
                content: url,
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

    </script>

    <script th:inline="javascript">
       /* var prefix = ctx + "zhmk/user"
        $("#form-user-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-user-add').serialize());
            }
        }*/

        /*$("input[name='pwdUpdateDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });*/
    </script>
</body>
</html>